﻿<%@ Page Title="POSSystem | Customer Order" Theme="POSSystem" Language="C#" MasterPageFile="~/Application.Master"
    AutoEventWireup="true" CodeBehind="CustomerOrders.aspx.cs" Inherits="WebUI.CustomerOrders" %>

<%@ Register Src="~/Controls/POSControls/CustomerOrders.ascx" TagName="CustomerOrders"
    TagPrefix="uc" %>
<%@ Register Src="~/Controls/POSControls/OrderItemsCtrl.ascx" TagName="OrderItems" TagPrefix="uc" %>
<%@ Register Src="~/Controls/SysControls/PageHeader.ascx" TagPrefix="uc" TagName="PageHeader" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ApplicationHeadHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ApplicationContentHolder" runat="server">
    <script type="text/javascript">
        function loadByOrderID() {
            if(stopRowClickEvent<%=gridOrder.ClientID %>){
                stopRowClickEvent<%=gridOrder.ClientID %> = false;
                return;
            }
            var ids = getSelectedItemID<%= gridOrder.ClientID %>();
            var hidOrderID = document.getElementById("<%= hidOrderID.ClientID %>");
            var btnLoadByOrderID = document.getElementById("<%=btnLoadByOrderID.ClientID %>");
            hidOrderID.value = ids;
            btnLoadByOrderID.click();
        }

        function onOrderClick() {
            var ids = getSelectedItemID<%= gridOrder.ClientID %>();
            if(ids == null || ids == ''){
                alert("No order was selected.");
                return false;
            }
            return true;
        }

        function onEditOrderDetails() {
            var id = getSelectedItemID<%=gridSelectedItems.ClientID %>();
            if(id == null){
                alert("No item was selected!");
                return false;
            }
            var returnValue = window.showModalDialog('<%=GetOrderDetailEditPageLink() %>' + 'mode=edit&id=' + id, '', 'dialogWidth=500px;dialogHeight=300px;resizable=no;help=no;unadorned=yes;');
            return returnValue > 0;
        }

        function onSale(){
            var w = screen.availWidth - 10;
            var id = getSelectedItemID<%=gridOrder.ClientID %>();
            if(id == null){
                alert("No item was selected!");
                return false;
            }

            var returnValue = window.showModalDialog('<%=GetSalePageLink() %>' + 'id=' + id, '', 'dialogWidth=' + w + 'px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
            var hidInvoiceID = document.getElementById("<%= hidInvoiceID.ClientID %>");
            hidInvoiceID.value = returnValue;
            return returnValue > 0;
        }

        function onShip()
        {
            var id = getSelectedItemID<%=gridOrder.ClientID %>();
            if(id == null){
                alert("No item was selected!");
                return false;
            }

            var returnValue = window.showModalDialog('<%=GetDateLink() %>', '', 'dialogWidth=300px;dialogHeight=300px;resizable=yes;help=no;unadorned=yes;');
            var hidShipDate = document.getElementById("<%= hidShipDate.ClientID %>");
            hidShipDate.value = returnValue;
            return returnValue != null && returnValue != undefined && returnValue != '';
        }

        function onRemoveOrder() {
            var id = HasCheckedItems<%=gridOrder.ClientID %>();
            if(id == false){
                alert("No item was selected!");
                return false;
            }
            
            return confirm("This action will delete all checked items. Do you want to continue?");
        }

        function onRemoveOrderItem() {
            var id = HasCheckedItems<%=gridSelectedItems.ClientID %>();
            if(id == false){
                alert("No item was selected!");
                return false;
            }
            
            return confirm("This action will delete all checked items. Do you want to continue?");
        }

        function showPrintDlg(key){
            var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
        }
    </script>
    <uc:PageHeader ID="pageHeader" Text="Customer Orders" ImageURL="~/Images/shopping-cart-icon.png"
        runat="server" />
    <table width="100%">
        <tr>
            <td style="width: 25%; text-align: left; vertical-align: top">
                <asp:Panel ID="panelCategory" runat="server" class="primaryPanel">
                    <div class="titleBar">
                        <asp:Label ID="lblTitle1" runat="server" CssClass="titleContent">Order List</asp:Label>
                    </div>
                    <div class="primaryFrameNoBorder">
                        <div>
                            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                <ContentTemplate>
                                    <table width="100%" class="toolbar">
                                        <tr>
                                            <td style='vertical-align: middle; width: 75px'>
                                                <asp:LinkButton class="tbbutton" ID="btnReload" runat="server" OnClick="btnReload_OnClick">
                                                    <img src="Images/reload.png" /><asp:Label ID="label11" runat="server" Text="Reload"></asp:Label>
                                                </asp:LinkButton>
                                                <img src="Images/tbSep.png" />
                                            </td>
                                            <td style='vertical-align: top; text-align: left; width:150px'>
                                                <asp:Label ID="label10" runat="server" Text="Status"></asp:Label>
                                                <asp:DropDownList ID="ddlStatus" runat="server" class='searchTextBox' AutoPostBack="true"
                                                    OnSelectedIndexChanged="ddlStatus_OnSelectedIndexChanged" Width="100px">
                                                </asp:DropDownList>
                                            </td>
                                            <td style='vertical-align: middle;'>
                                                <img src="Images/tbSep.png" />
                                                <asp:LinkButton class="tbbutton" ID="btnPending" runat="server" OnClick="btnPending_OnClick" OnClientClick="return onOrderClick();">
                                                    <img src="Images/npending.gif" /><asp:Label ID="label5" runat="server" Text="Pending"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnCreateInvoice" runat="server" OnClick="btnCreateInvoice_OnClick" OnClientClick="return onSale();">
                                                    <img src="Images/nInvoiceCreated.png" /><asp:Label ID="label4" runat="server" Text="Invoice Created"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnShip" runat="server" OnClick="btnShip_OnClick" OnClientClick="return onShip();">
                                                    <img src="Images/nshipped.gif" /><asp:Label ID="label3" runat="server" Text="Shipped"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnReject" runat="server" OnClick="btnReject_OnClick" OnClientClick="return onOrderClick();">
                                                    <img src="Images/nrejected.gif" /><asp:Label ID="label2" runat="server" Text="Rejected"></asp:Label>
                                                </asp:LinkButton>
                                                <asp:LinkButton class="tbbutton" ID="btnDeleteOrder" runat="server" OnClientClick="return onRemoveOrder();"
                                                    OnClick="btnRemoveOrder_OnClick">
                                                    <img src="Images/Delete.gif" /><asp:Label ID="label7" runat="server" Text="Delete"></asp:Label>
                                                </asp:LinkButton>
                                            </td>
                                        </tr>
                                    </table>
                                    <asp:UpdatePanel ID="updateGridOrder" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            <uc:CustomerOrders ID="gridOrder" Width="100%" runat="server" AllowPaging="true"
                                                AllowSorting="true" AllowSelecting="true" SaveOnCommit="false" />
                                            <asp:Label Text="(*) click on the status icon to view invoice if any." runat="server" class="labelNote"></asp:Label>
                                            <asp:HiddenField ID="hidInvoiceID" runat="server" />
                                            <asp:HiddenField ID="hidShipDate" runat="server" />
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                    <div style="height:20px" >&nbsp;</div>
                                    <asp:UpdatePanel ID="updateItems" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            <div id="divDetails" runat="server" style="display:none">
                                                <table width="100%" class="toolbar">
                                                    <tr>
                                                        <td style='vertical-align: middle;'>
                                                            <asp:LinkButton class="tbbutton" ID="btnPrintOrder" runat="server" OnClick="btnPrintOrder_OnClick">
                                                                <img src="Images/print.gif" /><asp:Label ID="label8" runat="server" Text="Print"></asp:Label>
                                                            </asp:LinkButton>
                                                            <img src="Images/tbSep.png" />
                                                            <asp:LinkButton class="tbbutton" ID="btnEditItem" runat="server" OnClientClick="return onEditOrderDetails();" OnClick="btnEditItem_OnClick">
                                                                <img src="Images/Edit.gif" /><asp:Label ID="label1" runat="server" Text="Edit"></asp:Label>
                                                            </asp:LinkButton>
                                                            <asp:LinkButton class="tbbutton" ID="btnDeleteItem" runat="server" OnClientClick="return onRemoveOrderItem();"
                                                                OnClick="btnRemoveOrderItem_OnClick">
                                                                <img src="Images/Delete.gif" /><asp:Label ID="label6" runat="server" Text="Delete"></asp:Label>
                                                            </asp:LinkButton>
                                                        </td>
                                                    </tr>
                                                </table>
                                                <uc:OrderItems Width="100%" ID="gridSelectedItems" runat="server" AllowPaging="false"
                                                    AllowSelecting="true" AllowSorting="false" ShowFooter="false" />
                                                <asp:Button ID="btnLoadByOrderID" runat="server" OnClick="btnLoadByOrderID_OnClick" style="display:none"/>
                                                <asp:HiddenField ID="hidOrderID" runat="server" />
                                            </div>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </div>
                    </div>
                </asp:Panel>
            </td>
        </tr>
    </table>
</asp:Content>
